import { Component, OnInit, Input, ChangeDetectorRef  } from '@angular/core';

@Component({
  selector: 'img-lazy-load',
  templateUrl: './img-lazy-load.component.html',
  styleUrls: ['./img-lazy-load.component.scss'],
})
export class ImgLazyLoadComponent implements OnInit {

  default: string = 'assets/default.gif';
  constructor(private changeDetectorRef:ChangeDetectorRef) { }

  @Input() src: string //要显示的图片

  ngOnInit() {
    
    let img = new Image();
    img.src = this.src;
    
    //这里为了达到演示效果给了两秒的延迟，实际使用中不需要延迟
    setTimeout(() => {
      // alert(this)
      if(this.default == '' || this.default == null){

      }else{
        this.default = this.src;
      }
      
    }, 500)
    this.changeDetectorRef.detectChanges()
  
  }

}
